import tensorflow as tf
import numpy as np
import os
from tensorflow.python.platform import gfile

os.environ["CUDA_VISIBLE_DEVICES"] = '-1'

# model_path = '/home/ubuntu/Ascend/models/tensorflow/tf.image.rgb_to_hsv/20221229_144221/tf.image.rgb_to_hsv_2.pb'
model_path = "/home/ubuntu/onnx_samples/onnx_transformer/source/tf.queue.FIFOQueue1.pb"
# input_path = '/home/ubuntu/Ascend/dataset/tensorflow/seed/tf.image.rgb_to_hsv/20221229_144221' \
#              '/tf.image.rgb_to_hsv_seeds.npz'


def run_model():
    sess = tf.compat.v1.Session()
    with gfile.FastGFile(model_path, "rb") as f:
        graph_def = tf.compat.v1.GraphDef()
        graph_def.ParseFromString(f.read())
        sess.graph.as_default()
        # import graph from sess
        tf.import_graph_def(graph_def, name="")

    # init tht session
    # sess.run(tf.compat.v1.global_variables_initializer())
    # x = sess.graph.get_tensor_by_name("x:0")
    op = sess.graph.get_tensor_by_name("result:0")

    # get the result of model
    # input_dict = np.load(input_path)
    # print("images: " + str(input_dict["images_2"]))
    # print("y: " + str(input_dict["y_529"]))
    # print(sess.run(op, feed_dict={
    #     "images:0": input_dict["images_2"]
    # }))
    # result = sess.run(op, feed_dict={
    #     "input:0": np.array([[1, 2], [3, 4]], dtype=np.int32)
    # })
    result = sess.run(op)
    print(result)


if __name__ == "__main__":
    run_model()
